package org.example.javawebday1.controller;

import org.example.javawebday1.pojo.Dept;
import org.example.javawebday1.pojo.Result;
import org.example.javawebday1.service.DeptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/depts")
@RestController
public class DeptsController {

    @Autowired
    private DeptsService deptsService;

//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping
    public Result getAllDepts() {
        return deptsService.getAllDepts();
    }

    @DeleteMapping
    public Result deleteDept(@RequestParam("id") Integer id) {
        return deptsService.deleteDeptById(id);
    }

//    @PostMapping("/depts")
//    public Result addDept(@RequestBody Dept dept) {
//        return deptsService.addDept(dept);
//    }

    @PostMapping
    public Result addDept(@RequestBody List<Dept> depts) {
        return deptsService.addDepts(depts);
    }

    @GetMapping("/{id}")
    public Result getDeptById(@PathVariable("id") Integer id) {
        return deptsService.getDeptById(id);
    }

    @PutMapping
    public Result updateDept(@RequestBody Dept dept) {
        return deptsService.updateDept(dept);
    }


}
